/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.duarte.empresa.ui;

import javax.swing.JOptionPane;
import org.duarte.empresa.bsl.Empregado;
import org.duarte.empresa.bsl.EmpregadoExisteException;
import org.duarte.empresa.bsl.EmpregadoNaoExisteException;
import org.duarte.empresa.bsl.Empresa;
import org.duarte.empresa.bsl.Gestor;
import org.duarte.empresa.bsl.Motorista;
import org.duarte.empresa.bsl.Normal;
import java.util.Observable;
import java.util.Observer;

/**
 *
 * @author duarteduarte
 */
public class MenuUI extends javax.swing.JFrame implements Observer {

    Empresa empresa;
    menuGestao menugestao = new menuGestao();

    class ComboItem {
        String description;

        public ComboItem(String value, String description)
        {
            this.value=value;
            this.description=description;
        }
        
        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
        String value;
        
        public String toString(){
            return this.description;
        }
    }
    
    /**
     * Creates new form MenuUI
     */
    public MenuUI() {
        initComponents();
        this.cbFunc.removeAllItems();
        empresa = new Empresa();
        empresa.setNome("BenficaTV");
        this.empresa.addObserver(this);
        
        this.cbFunc.addItem(new ComboItem("motorista", "Motorista"));
        this.cbFunc.addItem(new ComboItem("normal", "Empregado"));
        this.cbFunc.addItem(new ComboItem("gestor", "Gestor"));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnAddEmp = new javax.swing.JButton();
        btnConsEmp = new javax.swing.JButton();
        btnRemEmp = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        btnGest = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        tbNome = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        tbCod = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tbSal = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tbBonus = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        progTSal = new javax.swing.JProgressBar();
        progMSal = new javax.swing.JProgressBar();
        tbTSal = new javax.swing.JTextField();
        tbMSal = new javax.swing.JTextField();
        btnLimpar = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        passGest = new javax.swing.JPasswordField();
        jLabel12 = new javax.swing.JLabel();
        tbDias = new javax.swing.JTextField();
        tbValKM = new javax.swing.JTextField();
        tbNKM = new javax.swing.JTextField();
        btnEnterPass = new javax.swing.JButton();
        cbFunc = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(204, 0, 0));

        btnAddEmp.setText("Adicionar empregado");
        btnAddEmp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnAddEmpMouseClicked(evt);
            }
        });
        btnAddEmp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddEmpActionPerformed(evt);
            }
        });

        btnConsEmp.setText("Consultar empregado");
        btnConsEmp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnConsEmpMouseClicked(evt);
            }
        });
        btnConsEmp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConsEmpActionPerformed(evt);
            }
        });

        btnRemEmp.setText("Remover empregado");
        btnRemEmp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnRemEmpMouseClicked(evt);
            }
        });
        btnRemEmp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemEmpActionPerformed(evt);
            }
        });

        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("BENFICATV");

        btnGest.setText("Gestão da Empresa");
        btnGest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGestActionPerformed(evt);
            }
        });

        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Nome");

        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Função");

        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Código");

        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Salário");

        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
        jLabel7.setText("Dias");

        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Bonus");

        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setText("Massa Salarial");

        jLabel9.setForeground(new java.awt.Color(255, 255, 255));
        jLabel9.setText("Média Salarial");

        progTSal.setMaximum(100000);

        progMSal.setMaximum(10000);

        btnLimpar.setText("Limpar");
        btnLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimparActionPerformed(evt);
            }
        });

        jLabel10.setForeground(new java.awt.Color(255, 255, 255));
        jLabel10.setText("Valor p/ KM");

        jLabel11.setForeground(new java.awt.Color(255, 255, 255));
        jLabel11.setText("Nº KM");

        passGest.setText("jPasswordField1");
        passGest.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                passGestFocusGained(evt);
            }
        });

        jLabel12.setForeground(new java.awt.Color(255, 204, 0));
        jLabel12.setText("Password (gestão)");

        btnEnterPass.setBackground(new java.awt.Color(255, 204, 0));
        btnEnterPass.setText("enter");
        btnEnterPass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEnterPassActionPerformed(evt);
            }
        });

        cbFunc.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel3)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(8, 8, 8)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                        .add(jLabel5)
                                        .add(jLabel4))
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel6)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel2)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel7))
                                .add(18, 18, 18)
                                .add(cbFunc, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jPanel1Layout.createSequentialGroup()
                                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                            .add(tbNome)
                                            .add(tbCod)
                                            .add(tbSal)
                                            .add(tbBonus, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE))
                                        .add(106, 106, 106)
                                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                            .add(jPanel1Layout.createSequentialGroup()
                                                .add(3, 3, 3)
                                                .add(btnGest, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 179, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                            .add(btnAddEmp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 179, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(btnConsEmp)
                                            .add(btnRemEmp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 179, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                            .add(btnLimpar)))
                                    .add(jPanel1Layout.createSequentialGroup()
                                        .add(tbDias, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 62, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(26, 26, 26)
                                        .add(jLabel10)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(tbValKM, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 59, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(31, 31, 31)
                                        .add(jLabel11)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                        .add(tbNKM, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 58, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabel8)
                                    .add(jLabel12)
                                    .add(jLabel9))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(jPanel1Layout.createSequentialGroup()
                                        .add(passGest, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(2, 2, 2)
                                        .add(btnEnterPass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(progTSal, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)
                                    .add(progMSal, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .add(18, 18, 18)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(tbMSal, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(tbTSal, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(6, 6, 6)
                        .add(jLabel1)
                        .add(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jPanel1Layout.createSequentialGroup()
                                .add(55, 55, 55)
                                .add(btnAddEmp)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(btnConsEmp)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(btnRemEmp)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(btnLimpar))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                                .add(jLabel1)
                                .add(18, 18, 18)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(tbNome, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel3))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(jLabel4)
                                    .add(cbFunc, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(tbCod, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(tbSal, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel6))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                    .add(tbBonus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jLabel2))))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel7)
                            .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                .add(jLabel10)
                                .add(tbDias, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .add(tbValKM, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(tbNKM, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabel11)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                .add(jPanel1Layout.createSequentialGroup()
                                    .add(33, 33, 33)
                                    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                                        .add(jLabel12)
                                        .add(passGest, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .add(btnEnterPass))
                                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                    .add(jLabel8))
                                .add(btnGest))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, progTSal, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel9)
                            .add(progMSal, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                        .add(tbTSal, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tbMSal, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(7, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(28, 28, 28)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(71, 71, 71)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(137, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddEmpMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnAddEmpMouseClicked
    }//GEN-LAST:event_btnAddEmpMouseClicked

    private void btnAddEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddEmpActionPerformed
        // TODO add your handling code here:

        if (((ComboItem)this.cbFunc.getSelectedItem()).getValue().equals("motorista")) {
            Motorista e = new Motorista();
            e.setCodigo(this.tbCod.getText());
            e.setNome(this.tbNome.getText());
            e.setNumeroKm(Integer.parseInt(this.tbNKM.getText()));
            e.setValorKm(Integer.parseInt(this.tbValKM.getText()));
            try {
                empresa.insereEmpregado(e);
            } catch (EmpregadoExisteException eee) {
                javax.swing.JOptionPane.showMessageDialog(this, "Empregado " + this.tbCod.getText() + " já existe", "Erro", 0);
            }
        } else if (((ComboItem)this.cbFunc.getSelectedItem()).getValue().equals("gestor")) {
            Gestor e = new Gestor();
            e.setCodigo(this.tbCod.getText());
            e.setDias(Integer.parseInt(this.tbDias.getText()));
            e.setNome(this.tbNome.getText());
            e.setPremio(Integer.parseInt(this.tbBonus.getText()));
            e.setSalDia(Integer.parseInt(this.tbSal.getText()));
            try {
                empresa.insereEmpregado(e);
            } catch (EmpregadoExisteException eee) {
                javax.swing.JOptionPane.showMessageDialog(this, "Empregado " + this.tbCod.getText() + "já existe", "Erro", 0);
            }
        } else if (((ComboItem)this.cbFunc.getSelectedItem()).getValue().equals("normal")) {
            Normal e = new Normal();
            e = new Normal(Integer.parseInt(this.tbSal.getText()), this.tbCod.getText(), this.tbNome.getText(), Integer.parseInt(this.tbDias.getText()));
            e.setCodigo(this.tbCod.getText());
            e.setNome(this.tbNome.getText());
            e.setDias(Integer.parseInt(this.tbDias.getText()));
            e.setSalDia(Integer.parseInt(this.tbSal.getText()));
            try {
                empresa.insereEmpregado(e);
            } catch (EmpregadoExisteException eee) {
                javax.swing.JOptionPane.showMessageDialog(this, "Empregado " + this.tbCod.getText() + "já existe", "Erro", 0);
            }
        }


    }//GEN-LAST:event_btnAddEmpActionPerformed

    private void btnConsEmpMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnConsEmpMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_btnConsEmpMouseClicked

    private void btnConsEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsEmpActionPerformed
        // TODO add your handling code here:
        String cod = this.tbCod.getText();
        if (!cod.equals("")) {
            try {
                Empregado e = this.empresa.fichaEmpregado(cod);

                this.tbNome.setText(e.getNome());
                String funcao =e.getClass().getSimpleName().toLowerCase();
                ComboItem ci=null;
                for( int i=0;i<this.cbFunc.getItemCount();i++ ){
                    ci=(ComboItem)this.cbFunc.getItemAt(i);
                    if(ci.getValue().equals(funcao))
                        this.cbFunc.setSelectedItem(ci);
                }
                
                if (funcao.equals("motorista")) {
                    Motorista mot = (Motorista) e;
                    this.tbNKM.setText(mot.getNumeroKm() + "");
                    this.tbValKM.setText(mot.getValorKm() + "");
                } else if (funcao.equals("gestor")) {
                    Gestor ges = (Gestor) e;
                    this.tbBonus.setText(ges.getPremio() + "");
                    this.tbSal.setText(ges.getSalDia() + "");
                    this.tbDias.setText(ges.getDias() + "");
                }
            } catch (EmpregadoNaoExisteException a) {
                javax.swing.JOptionPane.showMessageDialog(this, "Empregado " + this.tbCod.getText() + " não existe!\nPor favor indique um código válido.", "Aluno inexistente", 0);
            }
        } else {
            javax.swing.JOptionPane.showMessageDialog(this, "Por favor indique um código", "Dados incompletos", 0);
        }
    }//GEN-LAST:event_btnConsEmpActionPerformed

    private void btnRemEmpMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnRemEmpMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_btnRemEmpMouseClicked

    private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimparActionPerformed
        // TODO add your handling code here:

        this.tbBonus.setText("");
        this.tbCod.setText("");
        
        this.cbFunc.setSelectedIndex(0);
        this.tbMSal.setText("");
        this.tbTSal.setText("");
        this.tbNome.setText("");
        this.tbSal.setText("");
        this.tbDias.setText("0");
        this.tbNKM.setText("0");
        this.tbValKM.setText("0");
        this.progMSal.setValue(0);
        this.progTSal.setValue(0);

    }//GEN-LAST:event_btnLimparActionPerformed

    private void passGestFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_passGestFocusGained
        // TODO add your handling code here:
    }//GEN-LAST:event_passGestFocusGained

    private void btnRemEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemEmpActionPerformed
        // TODO add your handling code here:

        if (!(this.tbCod.getText().equals(""))) {
            try {
                this.empresa.removeEmpregadoCod(this.tbCod.getText());
            } catch (EmpregadoNaoExisteException eee) {
                JOptionPane.showMessageDialog(null, eee.getMessage(), "Empregado não existe", JOptionPane.ERROR_MESSAGE);
            }
        } else {
            javax.swing.JOptionPane.showMessageDialog(this, "Por favor indique o código", "Dados incompletos", 0);
        }

    }//GEN-LAST:event_btnRemEmpActionPerformed

    private void btnGestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGestActionPerformed
        // TODO add your handling code here:
        int media = (int) (empresa.totalSalarios() / empresa.getLista().size());
        int total = (int) empresa.totalSalarios();
        this.progMSal.setValue(media);
        this.progTSal.setValue(total);
        this.tbTSal.setText(total + "");
        this.tbMSal.setText(media + "");
    }//GEN-LAST:event_btnGestActionPerformed

    public void update(Observable observable, Object obj) {
        int totalSal = (int) (this.empresa.totalSalarios());
        int mediaSal = (int) (this.empresa.totalSalarios() / this.empresa.getLista().size());
        this.progMSal.setValue(mediaSal);
        this.progTSal.setValue(totalSal);
        this.tbTSal.setText(""+totalSal);
        this.tbMSal.setText(""+mediaSal);
    }

    private void btnEnterPassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEnterPassActionPerformed
        // TODO add your handling code here:
        //if (this.passGest.getPassword().toString().equals("benfica")) {
        this.setVisible(false);
        menugestao.setVisible(true);
        //} else {
        //  javax.swing.JOptionPane.showMessageDialog(this, "Tente novamente", "Password incorrecta", 0);
        // }
    }//GEN-LAST:event_btnEnterPassActionPerformed

    public void consultaEmpregado(String codigo) {
        try {
            Empregado e = empresa.fichaEmpregado(codigo);

        } catch (EmpregadoNaoExisteException eee) {
            JOptionPane.showMessageDialog(null, eee.getMessage(), "Empregado não existe", JOptionPane.ERROR_MESSAGE);
        }
    }

    public Empresa getEmpresa(){
        return this.empresa;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;


                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MenuUI.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MenuUI.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MenuUI.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MenuUI.class
                    .getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MenuUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddEmp;
    private javax.swing.JButton btnConsEmp;
    private javax.swing.JButton btnEnterPass;
    private javax.swing.JButton btnGest;
    private javax.swing.JButton btnLimpar;
    private javax.swing.JButton btnRemEmp;
    private javax.swing.JComboBox cbFunc;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField passGest;
    private javax.swing.JProgressBar progMSal;
    private javax.swing.JProgressBar progTSal;
    private javax.swing.JTextField tbBonus;
    private javax.swing.JTextField tbCod;
    private javax.swing.JTextField tbDias;
    private javax.swing.JTextField tbMSal;
    private javax.swing.JTextField tbNKM;
    private javax.swing.JTextField tbNome;
    private javax.swing.JTextField tbSal;
    private javax.swing.JTextField tbTSal;
    private javax.swing.JTextField tbValKM;
    // End of variables declaration//GEN-END:variables
}
